# Maintainer: Alexey Pavlov <alexpux@gmail.com>

pkgbase=gettext
pkgname=('gettext' 'gettext-devel' 'libgettextpo' 'libasprintf' 'libintl')
pkgver=0.19.6
pkgrel=1
pkgdesc="GNU internationalization library"
arch=('i686' 'x86_64')
url="http://www.gnu.org/software/gettext/"
license=('GPL')
groups=('base-devel')
makedepends=('libiconv-devel')
options=(!docs)
source=(ftp://ftp.gnu.org/pub/gnu/gettext/${pkgname}-${pkgver}.tar.gz{,.sig}
        0.18.1.1-autopoint-V.patch
        0.19.3-localename.patch
        0.18.1.1-no-woe32dll.patch
        0.19.3-tests-cygwin.patch
        gettext-0.18.3.1-msys2.patch
        gettext-0.19.6-archive.patch)
md5sums=('6d1447f8c5c45c329371ef4bfe7d79a5'
         'SKIP'
         '76d2d4a22b8831497e83a3d4bd798c3c'
         'bb446a13cfa7de098ad45e41c24f30a6'
         '6d176c6fa8288d71d9c0bb068de4bcda'
         '344be5f308e2090c8d93841bd4dc9962'
         '486a854ea6d1f681e2e70d32155d1027'
         '428ab317d85bff48e9874471f5a5f1cd')

prepare() {
  cd "${srcdir}/${pkgname}-${pkgver}"

  # Cygwin patches
  patch -p2 -i $srcdir/0.18.1.1-autopoint-V.patch
  patch -p2 -i $srcdir/0.19.3-localename.patch
  patch -p2 -i $srcdir/0.18.1.1-no-woe32dll.patch
  patch -p2 -i $srcdir/0.19.3-tests-cygwin.patch

  # MSYS2 patch
  patch -p1 -i $srcdir/gettext-0.18.3.1-msys2.patch

  pushd gettext-tools/misc > /dev/null
    mkdir archive
    tar -xvf archive.dir.tar -C archive
    rm -f archive.dir.tar
    pushd archive > /dev/null
      patch -p1 -i ${srcdir}/gettext-0.19.6-archive.patch
      tar -cvf ../archive.dir.tar *
    popd > /dev/null
    rm -rf archive
  popd > /dev/null

  libtoolize --copy --force
  ./autogen.sh --skip-gnulib
}

build() {
  cd "${srcdir}/${pkgname}-${pkgver}"
  ./configure --build=${CHOST} \
    --prefix=/usr \
    --with-included-libcroco \
    --with-included-libunistring \
    --with-included-libxml \
    --with-included-glib \
    --with-included-gettext \
    --without-emacs \
    --enable-shared \
    --enable-static \
    --disable-java \
    --disable-native-java \
    --disable-csharp \
    --disable-openmp

  make

  make DESTDIR="${srcdir}/dest" install
  rm -f ${srcdir}/dest/usr/lib/charset.alias
}

check() {
  cd "${srcdir}/${pkgname}-${pkgver}"
  make check
}

package_gettext() {
  depends=('libintl' 'libgettextpo' 'libasprintf')
  install=gettext.install

  mkdir -p ${pkgdir}/usr/{bin,lib,share}

  cp -rf ${srcdir}/dest/usr/lib/gettext ${pkgdir}/usr/lib/

  cp -rf ${srcdir}/dest/usr/bin ${pkgdir}/usr/
  rm -rf ${pkgdir}/usr/bin/msys-asprintf-0.dll
  rm -rf ${pkgdir}/usr/bin/msys-gettextpo-0.dll
  rm -rf ${pkgdir}/usr/bin/msys-intl-8.dll

  cp -rf ${srcdir}/dest/usr/share/aclocal ${pkgdir}/usr/share/
  cp -rf ${srcdir}/dest/usr/share/doc ${pkgdir}/usr/share/
  cp -rf ${srcdir}/dest/usr/share/info ${pkgdir}/usr/share/
  cp -rf ${srcdir}/dest/usr/share/locale ${pkgdir}/usr/share/
  cp -rf ${srcdir}/dest/usr/share/man ${pkgdir}/usr/share/

}

package_gettext-devel() {
  pkgdesc="GNU Internationalization development utilities"
  groups=('development')
  depends=("gettext=${pkgver}" "libiconv-devel")
  options=('staticlibs')
  optdepends=('cvs: for autopoint tool')

  mkdir -p ${pkgdir}/usr/{bin,include,lib,share}

  cp -rf ${srcdir}/dest/usr/include ${pkgdir}/usr/
  cp -rf ${srcdir}/dest/usr/lib ${pkgdir}/usr/
  rm -rf ${pkgdir}/usr/lib/gettext
  cp -rf ${srcdir}/dest/usr/share/gettext ${pkgdir}/usr/share/
}

package_libintl() {
  pkgdesc="GNU Internationalization runtime library"
  groups=('libraries')
  depends=('gcc-libs' 'libiconv')

  mkdir -p ${pkgdir}/usr/bin
  cp -f ${srcdir}/dest/usr/bin/msys-intl-8.dll ${pkgdir}/usr/bin/
}

package_libgettextpo() {
  pkgdesc="GNU Internationalization runtime library"
  groups=('libraries')
  depends=('gcc-libs')

  mkdir -p ${pkgdir}/usr/bin
  cp -f ${srcdir}/dest/usr/bin/msys-gettextpo-0.dll ${pkgdir}/usr/bin/
}

package_libasprintf() {
  pkgdesc="C-style formatted output in C++ (runtime)"
  groups=('libraries')
  depends=('gcc-libs')

  mkdir -p ${pkgdir}/usr/bin
  cp -f ${srcdir}/dest/usr/bin/msys-asprintf-0.dll ${pkgdir}/usr/bin/
}
